package com.xingdata.jjxc.speech;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import com.amap.api.services.core.PoiItem;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechRecognizer;
import com.iflytek.cloud.ui.RecognizerDialog;
import com.iflytek.sunflower.FlowerCollector;
import com.xingdata.jjxc.R;
import com.xingdata.jjxc.adapter.PoiListViewAdapter;
import com.xingdata.jjxc.map.navi.IATController;

public class IatActivity extends Activity implements OnClickListener,
		OnItemClickListener {
	private String TAG = "IatActivity";
	// 语音听写对象
	private SpeechRecognizer mIat;
	// 用HashMap存储听写结果
	private HashMap<String, String> mIatResults = new LinkedHashMap<String, String>();
	// 引擎类型
	private String mEngineType = SpeechConstant.TYPE_CLOUD;
	private Boolean isSerchSuccess = false;
	// 语音听写UI
	private RecognizerDialog mIatDialog;
	private EditText mResultText;
	private int IatrequestCode = 2;
	private ListView poiListView;
	private PoiListViewAdapter adapter;
	private ArrayList<PoiItem> poiItems = new ArrayList<PoiItem>();
	private TextView remarkView;
	private IATController iatController;
	private Bundle mBundle;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.iat_listview);
		initView();
	}

	private void initView() {
		mBundle = getIntent().getExtras();
		poiItems = mBundle.getParcelableArrayList("poi");
		poiListView = (ListView) findViewById(R.id.Poi_ListView);
//		poiListView.setOnItemClickListener(this);
//		adapter = new PoiListViewAdapter(poiItems, IatActivity.this);
//		poiListView.setAdapter(adapter);
//		remarkView = (TextView) findViewById(R.id.remark);
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {

		default:
			break;
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (mIat != null) {
			// 退出时释放连接
			mIat.cancel();
			mIat.destroy();
		}

	}

	@Override
	protected void onResume() {
		// 移动数据统计分析
		FlowerCollector.onResume(IatActivity.this);
		FlowerCollector.onPageStart(TAG);
		super.onResume();
	}

	@Override
	protected void onPause() {
		// 移动数据统计分析
		FlowerCollector.onPageEnd(TAG);
		FlowerCollector.onPause(IatActivity.this);
		super.onPause();
	}


	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int position,
			long id) {
		Intent resultIntent = new Intent();
		Bundle bundle = new Bundle();
		bundle.putParcelable("poi", poiItems.get(position));
		resultIntent.putExtras(bundle);
		setResult(RESULT_OK, resultIntent);
		finish();
	}
}
